﻿namespace eProject.ViewModel.Commands
{
    public class DeleteEmployeeCommand: ICommand
    {
        private readonly CommonManager _manager;
        private readonly string _name;
        private readonly string _surname;
        private readonly string _phone;
        private readonly string _email;

        private int _index;


        private bool _isCanceled;
        private bool _isExecuted;

        public DeleteEmployeeCommand(CommonManager manager,EmployeeViewModel employee)
        {
            _manager = manager;
            _name = employee.Name;
            _surname = employee.Surname;
            _phone = employee.PhoneNumber;
            _email = employee.EMail;
        }

        public void Execute()
        {
            if (_isExecuted) return;
            var empl = _manager.GetEmployee(_email);
            _index = _manager.Employees.IndexOf(empl);
            _manager.DeleteEmployee(empl);
            
            _isExecuted = true;
            _isCanceled = false;
        }

        public void Unexecute()
        {
            if (_isCanceled) return;            
            _manager.CreateEmployee(_name, _surname, _phone, _email,_index);
            _isCanceled = true;
            _isExecuted = false;
        }
    }
}
